import time

from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop025"
content = '这个有优惠吗?'
firefox = openBrowser(url)
DBshopLogin(firefox,'yuqilin','123456')
#在首页的搜索框输入小米
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
#点击搜索按钮
firefox.find_element_by_xpath('//input[@type="submit"]').click()
#点击小米电视
firefox.find_element_by_xpath('//img[@alt="小米（MI）电视4A标准版 L55M5-AZ/L55M5-AD 55英寸"]').click()
#切换到第二个页面
switchWindow(firefox,2)
#点击商品咨询
firefox.find_element_by_link_text('商品咨询').click()

#输入咨询内容
firefox.find_element_by_id('goods_ask_content').send_keys(content)
time.sleep(3)
#点击提交咨询
firefox.find_element_by_xpath('//button[contains(text(),"提交咨询")]').click()
#等待数据提交
time.sleep(10)
#登陆后台
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"商品管理",'商品咨询')
#点击咨询回复
firefox.find_element_by_link_text('咨询回复').click()

firefox.find_element_by_id('reply_ask_content').send_keys('亲，这个是统一价，便宜不了')
firefox.find_element_by_xpath('//button[contains(text(),"回复商品咨询")]').click()
time.sleep(5)
try:
    firefox.find_element_by_xpath('//td[contains(.,"亲，这个是统一价，便宜不了")]')
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败"%testCase)
    getPhoto(firefox)

firefox.quit()